$(document).ready(function(){
    
    //bind modal
    $('a[data-toggle$="modal"]').each(function(){
        $(this).bind('click', function() {
                modalBoxByUrl($(this).attr('href'));
                return false;
            });
    });
    
    //bind Switch
    $('span[data-toggle$="switch"]').each(function(){
        var id = $(this).attr('id');
        var state = $(this).attr('state');
        var table = $(this).attr('table');
        var field = $(this).attr('field');
        
        
        $(this).html("<img width='52px' height='24px' src=\"/public/assets/sysadmin/images/switch_"+state+".png\" >");
        
        $(this).bind('click', function() {
            var itemObject = $(this);
            itemObject.html("<img src='/public/assets/sysadmin/images/loaders.gif'>");
            state == '1' ? state="2" : state="1";
            $.ajax({ 
                url: "/index.php/sysadmin/ajax/setStatus",
                type:"POST",    
                data: "table="+table+"&field="+field+"&id="+id+"&state="+state,
                success:function(msg){ 
                        itemObject.html("<img width='52px' height='24px' src=\"/public/assets/sysadmin/images/switch_"+state+".png\" >");
                      } 
             }); // end ajax.
            return false;
        }); // end bind click.
        
    }); // end each.
});